package cn.webrx;

import java.util.TreeMap;

public class TreeMap1 {
    public static void main(String[] args) {
        TreeMap<String, Integer> tm = new TreeMap<>(String::compareTo);
        tm.put("c", 100);
        tm.put("c++", 100);
        tm.put("java", 180);
        tm.put("go", 50);
        tm.put("basic", 5);
        tm.put("javascript", 100);
        System.out.println(tm);

        //升序
        TreeMap<Double, String> t2 = new TreeMap<>();
        //TreeMap<Double, String> t2 = new TreeMap<>(Double::compareTo);
        //乱序
        //TreeMap<Double, String> t2 = new TreeMap<>((a, b) -> Math.random()>.5 ? 1 : -1);
        //降序
        //TreeMap<Double, String> t2 = new TreeMap<>((a, b) -> a < b ? 1 : -1);
        //升序
        //TreeMap<Double, String> t2 = new TreeMap<>((a, b) -> a > b ? 1 : -1);
        t2.put(85d, "李四");
        t2.put(80d, "张三");
        t2.put(90d, "王五");
        t2.put(30d, "jack");
        System.out.println(t2);


        TreeMap<Student, String> t3 = new TreeMap<>((a,b)->a.getId()-b.getId());
        //key String
        t3.put(new Student(1,"李四1"),"郑州");
        t3.put(new Student(6,"李四2"),"北京");
        t3.put(new Student(2,"李四3"),"天津");
        t3.put(new Student(33,"李四33"),"上海");
        t3.put(new Student(4,"李四5"),"上海");
        System.out.println(t3);



    }
}
